package la.iok.hzsvn.lewin.movie.operation.controller;

import la.iok.hzsvn.lewin.movie.core.model.PlayRecordVo;
import la.iok.hzsvn.lewin.movie.operation.service.PlayRecordService;
import la.iok.hzsvn.share.response.ListDataResponse;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("internal-api/playRecords")
public class PlayRecordInternalController {
    private final PlayRecordService playRecordService;

    public PlayRecordInternalController(PlayRecordService playRecordService) {
        this.playRecordService = playRecordService;
    }

    @GetMapping("{id}")
    public SingleDataResponse<PlayRecordVo> playRecord(@PathVariable Long id){
        return new SingleDataResponse<>(playRecordService.po2vo(playRecordService.select(id)));
    }

    @GetMapping("movie/{movieId}/v/{version}")
    public SingleDataResponse<Integer> count(@PathVariable Long movieId, @PathVariable String version){
        return new SingleDataResponse<>(playRecordService.count(movieId,version));
    }

    @GetMapping("movie/{movieId}")
    public SingleDataResponse<Integer> count(@PathVariable Long movieId){
        return new SingleDataResponse<>(playRecordService.count(movieId,null));
    }
    @GetMapping("playing")
    public ListDataResponse<PlayRecordVo> playing(@RequestParam Long roomId){
        return new ListDataResponse<>(playRecordService.po2vo(playRecordService.roomPlayingRecords(roomId)));
    }
}
